
<script>
import ExtForm from '@/components/lt/codeGenerator/components/ExtForm'
import request from '@/utils/request'
import ExtTable from '@/components/lt/codeGenerator/components/ExtTable'
import moment from 'moment'
import {SysMixin} from '@/mixins/SysMixin'
import defaultSettings from '@/config/defaultSettings'
import pick from 'lodash.pick'
import ExtRow from '@/components/lt/codeGenerator/components/ExtRow'
export default {
    
    components:{ExtForm,ExtTable,ExtRow},
    mixins:[SysMixin],
   
    data(){
        return{
            width:800,
            defaultSettings,
            moment,
            visible:false,
            model:{},
            confirmLoading:false,
            title:'标题',
            pageMethods:null,//页面方法
            pageData:null,//页面数据
            timer:null,
            pick,
            request,
            isShowBootomButton:true,
  
        }
    },
    
    computed:{},
    watch:{},
    methods:{
        //动态添加监听
            // this.$watch('pageData',()=>{
            //     console.log(1111)
            // },{deep: true})
        pageEdit(){},
        edit (pageId,record) {
            // console.log(record)
            if(!pageId){
                return false
            }
            this.visible = true
            this.model = Object.assign({}, record)
            this.querySysPage(pageId)
        },
       
        querySysPage(pageId){
            this.confirmLoading=true
            request.get('/SysPageController/querySysPageById',{params:{pageId:pageId}}).then((res)=>{
                if (res.success) {
                    res.result.pageData = JSON.parse(require('js-base64').Base64.decode(res.result.pageData))
                    this.pageData = res.result.pageData
                    this.initDictCodes = res.result.pageDict
                    this.initSysPageMethods(this.pageData.code.methods)
                    this.initSysPageData(this.pageData.code.data)
                    this.$nextTick(() => {
                        this.timer = setTimeout(() => {this.pageEdit()}, 100)
                    })

                } else {
                    this.$message.warning(res.message)
                }
            }).finally(()=>{
                this.confirmLoading=false
            })
        },
        
        
        ok(){
            this.close()
        },
        cancel(){
            this.visible=false
        },
        close () {
            if(this.timer){
                clearTimeout(this.timer)
            }
            this.$emit('close')
            this.visible = false
        },
       
        
    },
    render: function(h) {
        if(this.pageData){
            const bottomButton = (
                <div class="drawer-bootom-button">
                    <a-button shape="round" onClick={this.cancel} style="margin-right: .8rem">取消</a-button>
                    <a-button  shape="round" onClick={this.ok} type="primary" >提交</a-button>
                </div>
            )
            return(
                <a-drawer destroyOnClose={true} placement="right" closable={true} visible={this.visible} maskClosable={true} width={this.width} title={this.title} onClose={this.cancel}>
                    <a-spin spinning={this.confirmLoading}>
                        {this.initSysPageComponents(h,this.pageData.components)}
                    </a-spin>
                    <div style="height:30px;"></div>
                    {this.isShowBootomButton?bottomButton:null}
                </a-drawer>  
            )
        }
    }

}
</script>



<style  scoped>
  .drawer-bootom-button {
    position: absolute;
    z-index: 999999;
    bottom: 0;
    width: 100%;
    /* border-top: 1px solid #e8e8e8; */
    padding: 10px 16px;
    text-align: right;
    left: 0;
    background: #fff;
    border-radius: 0 0 2px 2px;
  }

</style>